home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCX_LIB.ARJ / PCX_COMM.C next >
C/C++ Source or Header  |  1991-04-07  |  6KB  |  199 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  PCX_COMM.C - PCX_LIB Library Common Functions
  5.  *
  6.  *  Version:    1.00B
  7.  *
  8.  *  History:    91/02/14 - Created
  9.  *              91/04/01 - Release 1.00A
  10.  *              91/04/03 - fixed "segread" call.
  11.  *              91/04/07 - Release 1.00B
  12.  *
  13.  *  Compiler:   Microsoft C V6.0
  14.  *
  15.  *  Author:     Ian Ashdown, P.Eng.
  16.  *              byHeart Software
  17.  *              620 Ballantree Road
  18.  *              West Vancouver, B.C.
  19.  *              Canada V7S 1W3
  20.  *              Tel. (604) 922-6148
  21.  *              Fax. (604) 987-7621
  22.  *
  23.  *  Copyright:  Public Domain
  24.  *
  25.  *************************************************************************
  26.  */
  27.  
  28. /*
  29.  *************************************************************************
  30.  *
  31.  *  PORTABILITY NOTES
  32.  *
  33.  *  1.  While this program is written in ANSI C, it uses a number of 
  34.  *      function calls that are specific to the Microsoft C V6.0 library.
  35.  *      These are documented as follows for the purposes of porting this
  36.  *      program to other compilers and/or processors: 
  37.  *
  38.  *          int86x      - execute 80x86 interrupt routine (far data)
  39.  *          segread     - get current 80x86 segment register values
  40.  *
  41.  *************************************************************************
  42.  */
  43.  
  44. /*      INCLUDE FILES                                                   */
  45.  
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <dos.h>
  49. #include "pcx_int.h"
  50.  
  51. /*      FORWARD REFERENCES                                              */
  52.  
  53. /*      GLOBALS                                                         */
  54.  
  55. /*      PUBLIC FUNCTIONS                                                */
  56.  
  57. /*
  58.  *************************************************************************
  59.  *
  60.  *  PCX_OPEN - Open PCX Workblock
  61.  *
  62.  *  Purpose:    To allocate and initialize a PCX image file workblock.
  63.  *
  64.  *  Setup:      PCX_WORKBLK *pcx_open
  65.  *              (
  66.  *                char *fname,
  67.  *                BOOL wrt_flag
  68.  *              )
  69.  *
  70.  *  Where:      fname is a PCX image file name.
  71.  *              wrt_flag is a Boolean flag which if TRUE indicates that
  72.  *                the PCX image file is to be opened for writing;
  73.  *                otherwise it is opened for reading.
  74.  *
  75.  *  Return:     A pointer to a PCX image file workblock if successful;
  76.  *              otherwise NULL.
  77.  *
  78.  *************************************************************************
  79.  */
  80.  
  81. PCX_WORKBLK *pcx_open
  82. (
  83.   char *fname,
  84.   BOOL wrt_flag
  85. )
  86. {
  87.   PCX_WORKBLK *wbp;     /* PCX image file workblock pointer             */
  88.  
  89.   /* Allocate a workblock                                               */
  90.  
  91.   if ((wbp = (PCX_WORKBLK *) malloc(sizeof(PCX_WORKBLK))) == NULL)
  92.     return (NULL);
  93.  
  94.   /* Open the PCX image file in binary mode                             */
  95.  
  96.   if (wrt_flag == FALSE)
  97.     wbp->fp = fopen(fname, "rb");       /* Open for reading             */
  98.   else
  99.     wbp->fp = fopen(fname, "wb");       /* Open for writing             */
  100.  
  101.   if (wbp->fp == NULL)  /* Check for successful file opening            */
  102.   {
  103.     free(wbp);          /* Free the workblock memory                    */
  104.     return (NULL);
  105.   }
  106.  
  107.   return (wbp);         /* Return the workblock pointer                 */
  108. }
  109.  
  110. /*
  111.  *************************************************************************
  112.  *
  113.  *  PCX_CLOSE - Close PCX Workblock
  114.  *
  115.  *  Purpose:    To close a PCX image file and release its workblock
  116.  *              memory.
  117.  *
  118.  *  Setup:      BOOL pcx_close
  119.  *              (
  120.  *                PCX_WORKBLK *wbp
  121.  *              )
  122.  *
  123.  *  Where:      wbp is a PCX image file workblock pointer.
  124.  *
  125.  *  Return:     TRUE if successful; otherwise FALSE.
  126.  *
  127.  *************************************************************************
  128.  */
  129.  
  130. BOOL pcx_close
  131. (
  132.   PCX_WORKBLK *wbp
  133. )
  134. {
  135.   free(wbp->palettep);  /* Free the extended palette (if it exists)     */
  136.  
  137.   free(wbp);            /* Free the PCX image file workblock            */
  138.  
  139.   if (fclose(wbp->fp) == EOF)   /* Close the PCX image file             */
  140.     return (FALSE);
  141.  
  142.   return (TRUE);
  143. }
  144.  
  145. /*
  146.  *************************************************************************
  147.  *
  148.  *  PCX_ISVGA - Check For VGA Display Adapter
  149.  *
  150.  *  Purpose:    To determine whether a display adapter supports VGA BIOS
  151.  *              service routines.
  152.  *
  153.  *  Setup:      BOOL pcx_isvga(void)
  154.  *
  155.  *  Return:     TRUE if display adapter is VGA-compatible; otherwise
  156.  *              FALSE.
  157.  *
  158.  *************************************************************************
  159.  */
  160.  
  161. BOOL pcx_isvga(void)
  162. {
  163.   unsigned char *vinfop;        /* VGA information buffer pointer       */
  164.   union REGS regs;              /* 80x86 register values                */
  165.   struct SREGS sregs;           /* 80x86 segment register values        */
  166.  
  167.   /* Allocate a VGA functionality/state information buffer              */
  168.  
  169.   if ((vinfop = (unsigned char *) malloc(sizeof(unsigned char) * 64)) ==
  170.       NULL)
  171.     return (FALSE);
  172.  
  173.   /* Attempt to read the VGA information                                */
  174.  
  175.   regs.h.ah = 0x1b;     /* Select "Return VGA Info" BIOS routine        */
  176.   regs.x.bx = 0;        /* Implementation type                          */
  177.  
  178.   /* Get the VGA information buffer offset value                        */
  179.  
  180.   regs.x.di = (unsigned int) vinfop;
  181.  
  182.   segread(&sregs);      /* Get the current DS segment register value    */
  183.  
  184.   sregs.es = sregs.ds;
  185.  
  186.   int86x(0x10, ®s, ®s, &sregs);   /* Call BIOS video service      */
  187.  
  188.   free(vinfop);         /* Free the VGA information buffer              */
  189.  
  190.   /* The value 0x1b is returned in register AL only if a VGA display    */
  191.   /* adapter is present                                                 */
  192.  
  193.   if (regs.h.al == 0x1b)
  194.     return (TRUE);
  195.   else
  196.     return (FALSE);
  197. }
  198.  
  199.